Take an In-Depth Look at the %EVAL Function
نویسندگان
چکیده
EVAL is a widely used yet frequently misunderstood SAS macro language function due to its seemingly simple form. However, when its actual argument is a complex macro expression interlaced with special characters, mixed arithmetic and logical operators, or macro quotation functions, its usage and result become elusive and problematic. In this paper, we aim to explore and demystify the intricate part of %EVAL. First, we explain the mechanism that the SAS macro processor uses to invoke %EVAL, and point out the subtle difference between the implicit and explicit uses of %EVAL calls. Then, we reveal a series of hidden rules that %EVAL uses to manipulate its actual macro argument embedded with different types of special characters. Examples are provided to illustrate those rules and exceptions on a case-by-case basis. INTRODUCTION The %EVAL function evaluates integer arithmetic or logical expressions. %EVAL operates by converting its argument from a character value to a numeric or logical expression. Then it performs the evaluation. Finally, %EVAL converts the result back to a character value and returns that value. All parts of the macro language that evaluate expressions (for example, %IF and %DO statements) call %EVAL to evaluate the expressions. Unlike other SAS macro functions, the %EVAL function can be called explicitly and implicitly. It is often overlooked due to its seemingly simple implicit form. For most serious users, the %EVAL function frequently poses challenges. It appears elusive and problematic when its argument is a macro expression laced with special characters, mixed arithmetic and logical operators, or macro quoting functions. Consider the following simple example. The code produces the LOG shown in the box below. * Example 1; %macro notruth(x); %if &x=TRUE %then %put TRUE; %else %put FALSE; %mend; %notruth(TRUE) TRUE In this example, the %IF statement calls the %EVAL function implicitly to evaluate the logical expression &X=TRUE, where the macro parameter “X” is resolved as TRUE by the macro call. Since TRUE=TRUE, the condition is true, it writes TR UE in the LOG. However, you wouldn’t expect that each of the following macro calls also produces TRUE in the LOG. %notruth(FALSE <); TRUE %notruth(1 OR FALSE); TRUE %notruth(FALSE NE TRUE | TRUE); TRUE %notruth(LE OR ); TRUE %notruth(%str( TRUE)); TRUE Vice versa, we don’t expect the following call would produce FALSE in the LOG. %notruth(%quote( TRUE)) FALSE The complexity or the surprise in this example is mainly because what the actual argument resolves into changed the evaluation operation. Also, macro quotation functions have different effects on the expression. This paper aims to explore and demystify the intricate part of the %EVAL function. It discusses how macro processor handles a %EVAL function call, and how differently it treats explicit and implicit calls. We also summarize a series of rules which the %EVAL function uses to manipulate special characters and mixed arithmetic and logical expressions. Plenty of examples are presented to illustrate thos e hidden rules and exceptions. INVOCATION OF %EVAL FUNCTION A macro expression is any combination of text, macro variables, macro functions, or macro calls. When %EVAL is explicitly invoked to evaluate its argument: a macro expression, it internally performs the following two steps during execution time. 1. Resolution phase: Rescan the value of the actual argument to resolve the special macro symbols % and &. Normally, these two symbols indicate references to macro variables and macro calls that must be resolved prior to the evaluation; 2. Evaluation phase: Parse the resolved text from step 1 into arithmetic or logical operators and operands, and perform evaluation on this parsed expression. Example 2 shows the common warning and error messages associated with %EVAL function during these two different phases. Programming & Manipulation NESUG 17
منابع مشابه
تاثیر روان درمانی بر کارکرد و ساختار مغز
For many years scientists have tried hard and spent a lot of research budget in order to show the effect of medicine on brain , in the other hand our knowledge about how the psychotherapy works is nearly nothing. by considering the fact that psychotherapy has deep impression on emotion ,behavior and cognition it is expecting that it Influences the brains function a...
متن کاملVariation of Lithosphere-Asthenosphere boundary beneath Iran by using S Receiver function
The current geological and tectonic setting of Iran is due to the ongoing convergence between the Arabian and Eurasian Plates, which resulted in the formation of the Iranian plateau, mountain building, extensive deformation and seismicity. The Iranian plateau is characterized by various domains including the continental collision and the oceanic plate seduction. Based on S receiver functions ar...
متن کاملA Detailed look at Steganographic Techniques and their use in an Open-Systems Environment
This paper's focus is on a relatively new field of study in Information Technology known as Steganography. This paper will take an in-depth look at this technology by introducing the reader to various concepts of Steganography, a brief history of Steganography and a look at some of the Steganographic techniques available today. The paper will close by looking at how we can use Steganography in ...
متن کاملA Detailed look at Steganographic Techniques and their use in an Open-Systems Environment
This paper's focus is on a relatively new field of study in Information Technology known as Steganography. This paper will take an in-depth look at this technology by introducing the reader to various concepts of Steganography, a brief history of Steganography and a look at some of the Steganographic techniques available today. The paper will close by looking at how we can use Steganography in ...
متن کاملInvestigation into the Effects of Nanoparticle Size and Channel Depth on the Thermophysical Properties of Water Nanofluids in the Nanochannel Using Molecular Dynamics Simulation
In this research, an in-house code which uses the molecular dynamics method to study the flow of different nanofluids in the copper nanochannel and computes the thermo-physicals properties has been developed. The flow of nanofluids has been studied from hydro-thermally viewpoint and temperature jump at the wall has been applied. Parametric study to consider the effect of different parametric su...
متن کامل